package com.yuyou.fn.controller;

import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.arrangement.service.IArrangementService;
import com.yuyou.fn.common.constant.ClassLevelEnum;
import com.yuyou.fn.common.constant.JobNatureEnum;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.common.util.BigDecimals;
import com.yuyou.fn.common.util.EnumUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.educational.entity.*;
import com.yuyou.fn.educational.service.*;
import com.yuyou.fn.educational.vo.*;
import com.yuyou.fn.platform.entity.SysUser;
import com.yuyou.fn.platform.permission.DataPermission;
import com.yuyou.fn.report.service.IMergeStudentRegDetailService;
import com.yuyou.fn.util.Webs;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * Created by wens on 16-11-29.
 */
@Controller
@RequestMapping("/api/admin")
public class AdminCourseApiController extends ApiBaseController {

    private final static Logger log = LoggerFactory.getLogger(AdminCourseApiController.class);

    @Resource
    private ICourseTemplateService courseTemplateService;

    @Resource
    private ICourseClassService courseClassService;

    @Resource
    private ICourseTypeService courseTypeService;

    @Resource
    private IProductService productService;

	@Resource
	private ITeacherService teacherService;

    @Resource
    private IArrangementService arrangementService;

    @Resource
    private IStudentRegService studentRegService;

    @Resource
    private IMergeStudentRegDetailService mergeStudentRegDetailService;

    @ApiOperation("管理课程列表")
    @ApiImplicitParams({@ApiImplicitParam(value = "className", required = false), @ApiImplicitParam(value = "gradeName", required = false), @ApiImplicitParam(value = "subjectName", required = false), @ApiImplicitParam(value = "seniorName", required = false), @ApiImplicitParam(value = "roomName", required = false), @ApiImplicitParam(value = "periodName", required = false), @ApiImplicitParam(value = "progressStatus", required = false), @ApiImplicitParam(value = "campusName", required = false), @ApiImplicitParam(value = "openStatus", required = false), @ApiImplicitParam(value = "areaTeamName", required = false), @ApiImplicitParam(value = "busTeamName", required = false), @ApiImplicitParam(value = "areaTeamId", required = false), @ApiImplicitParam(value = "busTeamId", required = false)})
    @RequestMapping(value = "/courseTemplateManageList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CourseTemplate>> courseTemplateManageList(CourseTemplateQueryVo courseTemplateQuery, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);
        Page<CourseTemplate> page = courseTemplateService.findCourseTemplateByQueryForManage(courseTemplateQuery,dataPermission , pageNo, pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出课程列表")
    @ApiImplicitParams({@ApiImplicitParam(value = "className", required = false), @ApiImplicitParam(value = "gradeName", required = false), @ApiImplicitParam(value = "subjectName", required = false), @ApiImplicitParam(value = "seniorName", required = false), @ApiImplicitParam(value = "roomName", required = false), @ApiImplicitParam(value = "periodName", required = false), @ApiImplicitParam(value = "progressStatus", required = false), @ApiImplicitParam(value = "campusName", required = false), @ApiImplicitParam(value = "openStatus", required = false), @ApiImplicitParam(value = "areaTeamName", required = false), @ApiImplicitParam(value = "busTeamName", required = false), @ApiImplicitParam(value = "areaTeamId", required = false), @ApiImplicitParam(value = "busTeamId", required = false)})
    @RequestMapping(value = "/exportCourseTemplateByQueryForManage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CourseTemplate>> exportCourseTemplateByQueryForManage(CourseTemplateQueryVo courseTemplateQuery, HttpServletResponse response, HttpServletRequest request) throws Exception {
        DataPermission dataPermission = getDataPermission(request);
        Webs.writeExcel(request,response, courseTemplateService.exportCourseTemplateByQueryForManage(courseTemplateQuery,dataPermission), "课程列表");
        return ReturnResult.success("ok");
    }

    @ApiOperation("课程列表")
    @ApiImplicitParams({@ApiImplicitParam(value = "className", required = false), @ApiImplicitParam(value = "gradeName", required = false), @ApiImplicitParam(value = "subjectName", required = false), @ApiImplicitParam(value = "seniorName", required = false), @ApiImplicitParam(value = "roomName", required = false), @ApiImplicitParam(value = "periodName", required = false), @ApiImplicitParam(value = "progressStatus", required = false), @ApiImplicitParam(value = "campusName", required = false), @ApiImplicitParam(value = "openStatus", required = false), @ApiImplicitParam(value = "areaTeamName", required = false), @ApiImplicitParam(value = "busTeamName", required = false), @ApiImplicitParam(value = "areaTeamId", required = false), @ApiImplicitParam(value = "busTeamId", required = false)})
    @RequestMapping(value = "/courseTemplateUseList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CourseTemplate>> courseTemplateUseList(CourseTemplateQueryVo courseTemplateQuery, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);
        Page<CourseTemplate> page = courseTemplateService.findCourseTemplateByQueryForUse(courseTemplateQuery,dataPermission , pageNo, pageSize);
        return ReturnResult.success(page);
    }

	@ApiOperation("课程详情")
    @RequestMapping(value = "/courseTemplateDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CourseTemplate> courseTemplateDetail(@RequestParam("courseTemplateId") Long courseTemplateId) {
        CourseTemplate courseTemplate = courseTemplateService.findById(courseTemplateId);
        return ReturnResult.success(courseTemplate);
    }

	@ApiOperation("产品详情")
    @RequestMapping(value = "/productDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Product> productDetail(@RequestParam("productId") Long productId) {
        Product product = productService.findById(productId);
        return ReturnResult.success(product);
    }

	@ApiOperation("保存更新课程")
    @RequestMapping(value = "/saveOrUpdateCourseTemplate", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveOrUpdateCourseTemplate(@ModelAttribute CourseTemplateSaveOrUpdateVo courseTemplateSaveOrUpdateVo) {
        courseTemplateService.saveOrUpdateCourseTemplateList(courseTemplateSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("删除课程")
    @RequestMapping(value = "/deleteCourseTemplate", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> deleteCourseTemplate(@RequestParam("courseTemplateId") Long courseTemplateId ) {
        courseTemplateService.deleteCourse(courseTemplateId);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("保存更新产品")
    @RequestMapping(value = "/saveOrUpdateProduct", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveOrUpdateProduct(ProductSaveOrUpdateVo productSaveOrUpdateVo) {
        productService.saveOrUpdateProduct(productSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("更改课程")
    @RequestMapping(value = "/changeCourseStatus", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> changeCourseStatus(@RequestParam("courseTemplateId") Long courseTemplateId, @RequestParam("status") Integer status) {
        courseTemplateService.changeCourseStatus(courseTemplateId, status);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("课程类型列表")
    @RequestMapping(value = "/courseTypeList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CourseType>> courseTypeList(HttpServletRequest request) {

        List<CourseType> courseTypeList = courseTypeService.findAllCourseTypeFromCache();

        return ReturnResult.success(courseTypeList);
    }

    @ApiOperation("产品管理列表")
    @RequestMapping(value = "/productManageList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Product>> productManageList(ProductQueryVo productQueryVo, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);
        Page<Product> page = productService.findProductByQueryForManage(productQueryVo,dataPermission , pageNo, pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("产品列表")
    @RequestMapping(value = "/productUseList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Product>> productUseList(ProductQueryVo productQueryVo, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);
        Page<Product> page = productService.findProductByQueryForManage(productQueryVo,dataPermission , pageNo, pageSize);
        return ReturnResult.success(page);
    }

	@ApiOperation("更改产品")
    @RequestMapping(value = "/changeProductStatus", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> changeProductStatus(@RequestParam("productId") Long productId, @RequestParam("status") Integer status) {
        productService.changeProductStatus(productId, status);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("删除产品")
    @RequestMapping(value = "/deleteProduct", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> deleteProduct(@RequestParam("productId") Long productId) {
        productService.deleteProduct(productId);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("班级列表")
    @RequestMapping(value = "/courseClassList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CourseClass>> courseClassList(CourseClassQueryVo courseClassQueryVo, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {

        DataPermission dataPermission = getDataPermission(request);
        Page<CourseClass> page = courseClassService.findCourseClassByQueryForPage(courseClassQueryVo ,dataPermission , pageNo, pageSize);
        return ReturnResult.success(page);
    }

	@ApiOperation("班级详情")
    @RequestMapping(value = "/courseClassDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CourseClass> courseClassDetail(@RequestParam("courseClassId") Long courseClassId) {
        CourseClass courseClass = courseClassService.findById(courseClassId);
        CourseTemplate courseTemplate = courseTemplateService.findById(courseClass.getCourseTemplateId());
        ClassCourseVo classCourseVo = new ClassCourseVo();
        classCourseVo.setCourseClass(courseClass);
        classCourseVo.setCourseTemplate(courseTemplate);
        return ReturnResult.success(classCourseVo);
    }


    @ApiOperation("班级基本详情")
    @RequestMapping(value = "/courseClassBaseDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CourseClass> courseClassBaseDetail(@RequestParam("classId") Long classId) {
        CourseClass courseClass = courseClassService.findById(classId);
        return ReturnResult.success(courseClass);
    }

    @ApiOperation("保存更新班级")
    @RequestMapping(value = "/saveOrUpdateCourseClass", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveOrUpdateCourseClass(CourseClassSaveOrUpdateVo courseClassSaveOrUpdateVo) {
        courseClassService.saveOrUpdateCourseClass(courseClassSaveOrUpdateVo);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("保存更新班级状态")
    @RequestMapping(value = "/changeCourseClassStatus", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> changeCourseClassStatus(@RequestParam("status") Integer status , @RequestParam("classIds") String classIdsStr) {
        arrangementService.changeStatus(Utils.toLongIds(classIdsStr),status);
        return ReturnResult.success("Ok");
    }

	@ApiOperation("获取基础产品列表")
    @RequestMapping(value = "/baseProductList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Product>> baseProductList(HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);
        List<Product> list = productService.findBaseProductForUse(dataPermission);
        return ReturnResult.success(list);
    }

	@ApiOperation("获取基础产品列表(区域)")
    @RequestMapping(value = "/baseProductListForAreaTeam", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Product>> baseProductListForAreaTeam(@RequestParam(value = "areaTeamId",required = false) Long areaTeamId , HttpServletRequest request) {
        if(areaTeamId == null ){
            return ReturnResult.success(Collections.EMPTY_LIST);
        }
        List<Product> list = productService.findBaseProductByAreaTeamId(areaTeamId);
        return ReturnResult.success(list);
    }

	@ApiOperation("获取基础课程列表")
    @RequestMapping(value = "/baseCourseList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CourseTemplate>> baseCourseList(HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);

        List<CourseTemplate> list = courseTemplateService.findBaseCourse(dataPermission);
        return ReturnResult.success(list);
    }

    @ApiOperation("获取基础课程列表(区域)")
    @RequestMapping(value = "/baseCourseListForAreaTeam", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CourseTemplate>> baseCourseListForAreaTeam(@RequestParam(value = "areaTeamId",required = false) Long areaTeamId, HttpServletRequest request) {
        if (areaTeamId == null) {
            return ReturnResult.success(Collections.EMPTY_LIST);
        }
        List<CourseTemplate> list = courseTemplateService.findBaseCourseByAreaTeamId(areaTeamId);
        return ReturnResult.success(list);
    }

    @ApiOperation("导入班级Excel")
    @RequestMapping(value = "/courseClassImport", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult<Void> courseClassImport(HttpServletRequest request, MultipartFile file) throws Exception {
        InputStream inputStream = file.getInputStream();
        ImportParams params = new ImportParams();
        List<ImportCourseClassVo> importCourseClassVoList = ExcelImportUtil.importExcel(inputStream, ImportCourseClassVo.class, params);
        courseClassService.importCourseClass(importCourseClassVoList);
        return ReturnResult.success("OK");
    }



	@ApiOperation("导入课程Excel")
    @RequestMapping(value = "/courseTemplateImport", method = RequestMethod.POST)
    @ResponseBody
    public ReturnResult<Void> courseTemplateImport(HttpServletRequest request, MultipartFile file) throws Exception {
        SysUser user = getUser(request);
        InputStream inputStream = file.getInputStream();
        ImportParams params = new ImportParams();
        List<CourseTemplate> courseTemplateList = ExcelImportUtil.importExcel(inputStream, CourseTemplate.class, params);
        courseTemplateService.saveOrUpdateCourseTemplateList(courseTemplateList, user);
        return ReturnResult.success("ok");
    }


	@ApiOperation("推荐班级")
    @RequestMapping(value = "/recommendCourseClass", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> recommendCourseClass(@RequestParam("classIds[]") List<Long> classIds , @RequestParam("isRecommend") Integer isRecommend ) {
        courseClassService.recommendCourseClass(classIds,isRecommend);
        return ReturnResult.success("Ok");
    }



	@ApiOperation("课程类型列表")
	@RequestMapping(value = "/courseTypeManageList", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ReturnResult<Page<CourseType>> courseTypeManageList(
			@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
			@RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {
		DataPermission dataPermission = getDataPermission(request);
		Page<CourseType> page = courseTypeService.findCourseTypeByQueryForManage(dataPermission, pageNo, pageSize);
		return ReturnResult.success(page);
	}

	@ApiOperation("保存更新课程类型")
	@RequestMapping(value = "/saveOrUpdateCourseType", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ReturnResult<Void> saveOrUpdateCourseType(CourseTypeSaveOrUpdateVo courseTypeSaveOrUpdateVo) {
		courseTypeService.saveOrUpdateCourseType(courseTypeSaveOrUpdateVo);
		return ReturnResult.success("Ok");
	}

	@ApiOperation("删除课程类型")
	@RequestMapping(value = "/deleteCourseType", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public ReturnResult<Void> deleteCourseType(@RequestParam("courseTypeId") Long courseTypeId) {
		courseTypeService.deleteCourseType(courseTypeId);
		return ReturnResult.success("Ok");
	}


    @ApiOperation("获取地区课程列表")
    @RequestMapping(value = "/baseCourseTemplateListForAreaTeam", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public ReturnResult<List<CourseTemplate>> baseCourseTemplateListForAreaTeam(@RequestParam("areaTeamId") Long areaTeamId) {
        List<CourseTemplate> list = courseTemplateService.findBaseCourseByAreaTeamId(areaTeamId);
        return ReturnResult.success(list);
    }

    @ApiOperation("获取地区期数课程列表")
    @RequestMapping(value = "/baseCourseTemplateListForAreaTeamPeriod", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public ReturnResult<List<CourseTemplate>> baseCourseTemplateListForAreaTeamPeriod(@RequestParam("areaTeamId") long areaTeamId,@RequestParam("periodIds")String periodIds) {
        List<CourseTemplate> list = courseTemplateService.findBaseCourseByAreaTeamIdPeriodIds(areaTeamId,Utils.toLongIds(periodIds));
        return ReturnResult.success(list);
    }


    @ApiOperation("主任列表")
    @RequestMapping(value = "/seniorList", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public ReturnResult<Page<Teacher>> seniorList(@RequestParam("areaTeamId") Long areaTeamId , @RequestParam(value = "teacherName" , required = false) String teacherName ,@RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize, HttpServletRequest request) {
        TeacherQueryVo teacherQueryVo = new TeacherQueryVo();
        teacherQueryVo.setStatus(1);
        teacherQueryVo.setAreaTeamId(areaTeamId);
        teacherQueryVo.setTeacherName(teacherName);
        teacherQueryVo.setAccessTypes(Arrays.asList(1,2));
        Page<Teacher> page = teacherService.findTeacherByBusTeamListForPage(teacherQueryVo, null, pageNo, pageSize);
        return ReturnResult.success(page);
    }


    @ApiOperation("设置班主任")
    @RequestMapping(value = "/setupClassSenior", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public ReturnResult<Void> setupClassSenior(@RequestParam("teacherId") Long teacherId , @RequestParam("classIds[]") Long[] classIds) {
        courseClassService.updateSenior(classIds,teacherId);
        return ReturnResult.success("OK");
    }

    @ApiOperation("单个设置学生报名信息班主任")
    @RequestMapping(value = "/setupStudentRegSenior", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public ReturnResult<Void> setupStudentRegSenior(@RequestParam("teacherId") Long teacherId , @RequestParam("regId") long regId) {
        studentRegService.updateSeniorByRegId(regId,teacherId);
        return ReturnResult.success("OK");
    }

    @ApiOperation("导出班级信息")
    @RequestMapping(value = "/exportCourseClassList", method = { RequestMethod.GET, RequestMethod.POST })
    public void exportCourseClassList(CourseClassQueryVo courseClassQueryVo , HttpServletRequest request, HttpServletResponse response) throws IOException {

        DataPermission dataPermission = getDataPermission(request);
        List<Product> productList=productService.findBaseProductByAreaTeamId(courseClassQueryVo.getAreaTeamId());
        List<CourseTemplate> courseTemplateList=courseTemplateService.findBaseCourseByAreaTeamId(courseClassQueryVo.getAreaTeamId());
        Map<Long, Product> productMap = BeanUtils.toMap(productList, "productId");
        Map<Long,CourseTemplate> courseTemplateMap=BeanUtils.toMap(courseTemplateList,"courseTemplateId");
        Page<CourseClass> page = courseClassService.findCourseClassByQueryForPage(courseClassQueryVo ,dataPermission , 1, 50000);

        SXSSFWorkbook excel = new SXSSFWorkbook();

        SXSSFSheet sheet = excel.createSheet("排课信息");

        SXSSFRow firstRow = sheet.createRow(0);

        String[] titles = new String[] { "班级编号","班级名称","层级","状态","开课日期","上课时间","结课日期","校区","教室","已上/总讲次","已报人数","学位数","主讲教师","任教性质","班主任","学费","期数","段次","年级","科目","众筹","区域","业务组","课程名称","产品名称"} ;

        for (int i = 0; i < titles.length; i++) {

            SXSSFCell cell = firstRow.createCell(i);
            cell.setCellValue(titles[i]);
        }

        List<CourseClass> courseClassList = page.getRecords();

        Map<String,String> statusMap = new HashMap<>();
        statusMap.put("0","初始化");
        statusMap.put("1","报名中");
        statusMap.put("2","已作废");
        statusMap.put("3","已结课");

        Map<String,String> classTypeMap = new HashMap<>();
        classTypeMap.put("0","否");
        classTypeMap.put("1","是");




        for (int i = 0; i < courseClassList.size(); i++ ) {

            SXSSFRow row = sheet.createRow(i + 1);

            CourseClass courseClass = courseClassList.get(i);

            int c = 0;
            SXSSFCell cell = row.createCell(c++);
            cell.setCellValue(courseClass.getClassNo());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getClassName());

            cell = row.createCell(c++);
            cell.setCellValue(EnumUtils.getName(ClassLevelEnum.values() ,courseClass.getLevel()));

            cell = row.createCell(c++);
            cell.setCellValue(statusMap.get(String.valueOf(courseClass.getStatus())));

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getStartCourseTime() == null ? StringUtils.EMPTY : Utils.formatDate(courseClass.getStartCourseTime() , "yyyy-MM-dd"));

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getStudyingTime());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getEndCourseTime() == null ? StringUtils.EMPTY : Utils.formatDate(courseClass.getEndCourseTime() , "yyyy-MM-dd"));

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getCampusName());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getRoomName());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getCompletedLectureAmount() +"/" + courseClass.getLectureAmount() );

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getRegAmount());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getQuota());


            cell = row.createCell(c++);
            cell.setCellValue(StringUtils.defaultString(courseClass.getTeacherName()));

            cell = row.createCell(c++);
            cell.setCellValue(EnumUtils.getName(JobNatureEnum.values() ,courseClass.getJobNature()));



            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getSeniorName());

            cell = row.createCell(c++);
            cell.setCellValue(BigDecimals.formatBigDecimal(courseClass.getStudyingFee(),"0.00"));

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getPeriodName());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getSegmentNo()==null?"":courseClass.getSegmentNo().toString());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getGradeName());

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getSubjectName());

            cell = row.createCell(c++);
            cell.setCellValue(classTypeMap.get(String.valueOf(courseClass.getClassType())));

            cell = row.createCell(c++);
            cell.setCellValue( courseClass.getAreaTeamName() );

            cell = row.createCell(c++);
            cell.setCellValue(courseClass.getBusTeamName());

            CourseTemplate courseTemplate=courseTemplateMap.get(courseClass.getCourseTemplateId());
            cell = row.createCell(c++);
            cell.setCellValue(courseTemplate==null?"":StringUtils.defaultString(courseTemplate.getCourseName()));

            Product product=productMap.get(courseClass.getProductId());
            cell = row.createCell(c++);
            cell.setCellValue(product==null?"":StringUtils.defaultString(product.getName()));


        }

        Webs.writeExcel(request,response, excel , "排课信息");

    }

    @ApiOperation("复制初始化班级")
    @RequestMapping(value = "/copyInitOtherClassByOne", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public ReturnResult<Void> copyInitOtherClassByOne(@RequestParam("classId") long classId ) {
        courseClassService.copyInitOtherClassByOne(classId);
        return ReturnResult.success("OK");
    }

}